package homework_JDBC.zhangmu.dao;

import com.neu.dao.BaseDao;

import java.util.List;
import java.util.Map;

public class ZhangmuDaoImpl extends BaseDao implements ZhangmuDao {
    @Override
    public int addzhangmu(String type, String name, String money, String date) {
        int row = 0;
        String sql = "INSERT INTO tbl_zhangmu(zhangmu_type,zhangmu_name,zhangmu_money,zhangmu_date)\n" +
                " VALUES(?,?,?,?)";
        row = super.executeUpdate(sql, type, name, money, date);
        return row;
    }

    @Override
    public int updatezhangmu(String type, String name, String money, String date, String id) {
        int row = 0;
        String sql = "UPDATE tbl_zhangmu\n" +
                " set zhangmu_type=?,zhangmu_name=?,zhangmu_money=?,zhangmu_date=?\n" +
                " WHERE zhangmu_id=?";
        row = super.executeUpdate(sql, type, name, money, date, id);
        return row;
    }

    @Override
    public List<Map<String, Object>> searchzhangmuAll() {
        List<Map<String, Object>> list = null;
        String sql = "SELECT *\n" +
                " FROM tbl_zhangmu";
        list = super.executeQuery(sql);
        return list;
    }

    @Override
    public List<Map<String, Object>> searchzhangmuByDate(String date1, String date2) {
        List<Map<String, Object>> list = null;
        String sql="SELECT *\n" +
                "FROM tbl_zhangmu\n" +
                "WHERE zhangmu_date BETWEEN ? AND ?";
        list=super.executeQuery(sql,date1,date2);
        return list;
    }

    @Override
    public int deletezhangmu(String id) {
        int row=0;
        String sql="DELETE FROM tbl_zhangmu\n" +
                "WHERE zhangmu_id=?";
        row=super.executeUpdate(sql,id);
        return row;
    }
}
